<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
<form name="myForm">
	<input name="a" type="text" >+
	<input name="b" type="text" >
	<button name="btn">=</button>
	<input name="sum" type="text" >
</form>
<script>
	// document.myForm.btn.onclick = function(e){
	// 	alert(1);
	// 	e.preventDefault();
	// }
	
	document.myForm.onsubmit = function(e){
		e.preventDefault();
		// console.log(this===document.myForm);// true
		const xhr = new XMLHttpRequest();
		xhr.responseType = "json";
		xhr.open("get",`/sum?a=${this.a.value.trim()}&b=${this.b.value.trim()}`);
		xhr.send();
		xhr.onload = function(){
			if(xhr.response.ok === 1){
				document.myForm.sum.value = xhr.response.sum
			}else{
				alert(xhr.response.msg)
			}
		}
	}
</script>
</body>
</html>